package com.yalemang.photovalut.ui.calculator.adapter

import UserManager
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.jeremyliao.liveeventbus.LiveEventBus
import com.yalemang.framework.base.BaseVBAdapter
import com.yalemang.photovalut.base.BaseChickAdapter
import com.yalemang.photovalut.base.user.Skin
import com.yalemang.photovalut.databinding.ItemCalculatorSkinBinding

class SkinAdapter(private var skinList: ArrayList<Skin>) :
    BaseVBAdapter<Skin, ItemCalculatorSkinBinding>(skinList) {
    override fun onBindViewHolder(
        holder: CommonViewHolder<ItemCalculatorSkinBinding>,
        data: Skin,
        position: Int
    ) {
        val skin = skinList[position]
        holder.binding.viewLeft.setBackgroundColor(skin.mainColor)
        holder.binding.viewRight.setBackgroundColor(skin.viceColor)

        holder.itemView.setOnClickListener {
            UserManager.instance.updateSkin(skin)
            //发送广播
            LiveEventBus
                .get(Skin.KEY_SWITCH_SKIN_EVENT, Skin::class.java)
                .post(skin)
        }
    }
}